package com.ahuan.service.Impl;

import com.ahuan.domain.Menu;
import com.ahuan.domain.User;
import com.ahuan.mapper.LoginMapper;
import com.ahuan.service.LoginService;
import com.ahuan.utils.TreeBuilder1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class LoginServiceImpl implements LoginService {

    @Autowired
    LoginMapper loginMapper;

    @Override
    public User login(String username, String password) {
        return loginMapper.selectByUserName(username, password);
    }

    @Override
    public List<Menu> queryMenu(String userId) {
        List<Menu> list = loginMapper.selectMenuList(userId);
        TreeBuilder1<Menu> treeBuilder = new TreeBuilder1<>(list,"menuId","pMenuId","menus");
        List<Menu> menuTree = treeBuilder.buildTree("0");//将菜单列表树化

        return menuTree.get(0).getMenus();//不要将导航栏菜单一起返回
    }
}
